﻿var currentHotButton;
var currentRecButton;

$(function () {
    $('.deleteeventbutton').click(function () {
        if (confirm("真的要删除这个活动吗？")) {

            var btn = $(this);
            $.post(
            relRootPath + '/Mod/Events/EventServices.asmx/DeleteEvent',
            { eventId: btn.attr('eid') },
            function (data, s, x) {
                btn.parents('tr').remove();
            });
        }
    });

    $('.hotbutton').click(function () {
        currentHotButton = $(this);
        $.post(
            relRootPath + '/Mod/Events/EventServices.asmx/SetHot',
            { eventId: currentHotButton.attr('eid') },
            SetHotResult
            );
    });

    $('.recbutton').click(function () {
        currentRecButton = $(this);
        $.post(
            relRootPath + '/Mod/Events/EventServices.asmx/SetRecommended',
            { eventId: currentRecButton.attr('eid') },
            SetRecResult
            );
    });
});

function SetHotResult(data, s, x) {
    var hot = eval($(data).text());
    if (hot != null) {
        var imgsrc = relRootPath + "/Content/images/icons/";
        var alt;
        if (!hot) {
            alt = "设置为热";
            imgsrc += "fire_off.png";
        }
        else {
            alt = "取消热";
            imgsrc += "fire_on.png";
        }

        currentHotButton.attr('title', alt);
        currentHotButton.find('img').attr('src', imgsrc).attr('title', alt) ;

    }
    else {
        alert("数据库或通讯错误。");
    }
}

function SetRecResult(data, s, x) {
    var hot = eval($(data).text());
    if (hot != null) {
        var imgsrc = relRootPath + "/Content/images/icons/";
        var alt;
        if (!hot) {
            alt = "设置为精华";
            imgsrc += "star_off.png";
        }
        else {
            alt = "取消精华";
            imgsrc += "star_on.png";
        }

        currentRecButton.attr('title', alt);
        currentRecButton.find('img').attr('src', imgsrc).attr('title', alt);

    }
    else {
        alert("数据库或通讯错误。");
    }
}